<?php

class Pageley_Mock_Recording {
    private $key;
    private $executionObject;
    private $returnValue;
    private $methodName;
    private $exception;
    
    public function __construct($key) {
        $this->key = $key;
    }
    
    public function andExecute($executionObject, $methodName) {
        $this->executionObject = $executionObject;
        $this->methodName = $methodName;
        return $this;
    }
    
    public function andReturn($returnValue) {
        $this->returnValue = $returnValue;
        return $this;
    }
    
    public function andThrow($exception) {
        $this->exception = $exception;
        return $this;
    }
    
    public function execute($parameters) {
        if($this->executionObject !== null) {
            $methodName = $this->methodName;
            $this->executionObject->$methodName($parameters);
        }
        if($this->exception != null) {
            throw $this->exception;
        }
        return $this->returnValue;
    }
    
    public function getKey() {
        return $this->key;
    }
}